<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" type="text/css" href="../../../CSS/default.css" />
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">

	</head>

	<body style="background-color: white;padding: 0px;">
		<div id="toolbar" class="receipts_toolbar_style"></div>
		<form id="ff" method="post" style="margin-left: 10%;">
			<div style="display: none;">
				<input id="input_ID" class="easyui-textbox" type="text" name="ID" style="width:50%;"></input>
			</div>
			<table cellpadding="3" class="displaytable" style="padding: 20px;">
				<tr>
					<td width="30%">
						<h id="star">* </h>周期名称
					</td>
					<td width="68%">
						<div id="input_CYCLENAME" class="easyui-textbox" name="CYCLENAME" style="width:100%" data-options="required:true"></div>
					</td>
				</tr>
				<tr>
					<td>
						<h id="star">* </h>检查时间
					</td>
					<td>
						<div id="input_EXAMINATION_TIME" class="easyui-datebox" name="EXAMINATION_TIME" style="width:100%" data-options="required:true"></div>
					</td>
				</tr>
				<tr>
					<td>
						<h id="star">* </h>周期类型
					</td>
					<td>
						<div id="input_EXAMINATION_TYPE" class="easyui-combobox" name="EXAMINATION_TYPE" style="width:100%" data-options="required:true"></div>
					</td>
				</tr>
				<tr>
					<td>
						<h id="star">* </h>提前天数
					</td>
					<td>
						<input id="input_REMIND_TIME" class="easyui-textbox" name="REMIND_TIME" style="width:100%" data-options="required:true"></input>
					</td>
				</tr>
				<tr>
					<td>
						<h id="star">* </h>是否启用
					</td>
					<td>
						<div id="input_ISACTIVE" class="easyui-switchbutton" name="STATE" style="width:50%" data-options="required:true"></div>
					</td>
				</tr>
			</table>
		</form>
	</body>
	<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
	<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../../JS/common.js"></script>
	<script type="text/javascript" src="../../../JS/MarketShareFunction/FoodCycleShare.js"></script>
	<script type="text/javascript">
		var receipts_type = RECEIPT_SAVE_SYMBOL + RECEIPT_ADD_SYMBOL + RECEIPT_DELETE_SYMBOL;
		content = AddReceiptsToolBar(receipts_type, "");
		$("#toolbar").append(content); /*在ID=toolbar的标记后面添加content中的内容*/
		var currSTATE;
		var id = getID();
		console.log(id);
		$(document).ready(function(){
		if(id != AddFlag && id != undefined) {
			loadRemote();
		}else{
			id = AddFlag;
		}
		});

		$('#input_EXAMINATION_TYPE').combobox({
			data: EXAM_TYPE,
			method: 'get',
			valueField: "value",
			textField: "text",
			lines: true,
			panelHeight: 'auto',
			singleSelect: true,
		});
		
		
		function newdata(){
			id = AddFlag;
			$("#ff").form("reset");
		}

		$('#input_ISACTIVE').switchbutton({
			onText: '启用',
			offText: '不启用',
			onChange: function(checked) {
				if(checked) {
					currSTATE = 1;
				} else {
					currSTATE = 0;
				}
			}
		})

		function save() {
			var isValid = $("#ff").form('validate');
			if(!isValid) {
				$.messager.alert("警告", "有必填项没有填写");
				return;
			}
			SaveData();
		}

		function loadRemote() {
			_url = RemoteLinkAddress + '/market/examinationcycle/findbyid.do?ID=' + id;
			$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
				type: "get",
				url: _url,
				dataType: "json", //服务器返回的数据类型
				success: function(result) {
					if(result != null) {
						getFormData(result);
						id = result.ID;
						if(result.ISACTIVE == 1) {
							$("#input_ISACTIVE").switchbutton('check');
						} else {
							$("#input_ISACTIVE").switchbutton('uncheck');
						}
					}
				}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
				error: function(xhr, status, error) {
					$.messager.alert("错误", "请求失败!");
				}
			});
		}

		function cls() {
			$('#ff').form('reset');
		}

		function SaveData() {
			var _url = '';
			data = $('#ff').serialize();
			data += "&ISACTIVE=" + currSTATE;
			if(id != AddFlag) {
				_url = RemoteLinkAddress + "/market/examinationcycle/update.do";
			} else {
				_url = RemoteLinkAddress + "/market/examinationcycle/save.do";
			}

			$.post(_url, data,
				function(result) {
					if(result.msg.search("success") > -1) {
						var parentLocation;
						parentLocation = searchParent("FoodSecurityCycleList.html");
						parentLocation.dialogClose();
						$.messager.alert({ // show error message
							title: '成功',
							msg: '添加成功'
						});
					} else {
						$.messager.alert({ // show error message
							title: '错误',
							msg: result.msg
						});
					}
				},
				'json');
		}

		function deletedata() { //删除
			if(id == AddFlag) {
				$.messager.alert("提示", "该页面为新增页面，不能进行删除操作！");
				return;
			}
			$.messager.confirm('Confirm', '是否删除', function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/market/examinationcycle/delete.do", {
							ID: id
						},
						function(result) {
							if(result.msg == "success") {
								var parentLocation;
								parentLocation = searchParent("FoodSecurityCycleList.html");
								parentLocation.dialogClose();
								$.messager.alert({ // show success message
									title: '成功',
									msg: '删除成功'
								});
							} else {
								$.messager.alert({ // show error message
									title: 'Error',
									msg: result.msg
								});
							}
						},
						'json');
				}
			});
		}
	</script>

</html>